<?php

class Users_model extends CI_Model {

    function username_check($username) {

        $this->db->where('username', $username);
        $query = $this->db->get('users');
        if ($query->num_rows() > 0) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function email_check($email) {


        $this->db->where('email', $email);
        $query = $this->db->get('users');
        if ($query->num_rows() > 0) {
            return FALSE;
        } else {
            return TRUE;
        }
    }

    function insert_user($name, $username, $email, $password, $activation_code) {

        $data = array(
            'name' => $name,
            'username' => $username,
            'email' => $email,
            'password' => $password,
            'activation_code' => $activation_code
        );
        return $this->db->insert('users', $data);
    }

    function confirm_registration($activation_code) {       //busca codigo de verificacion en la base y si coincide cambia status a 1
        $this->db->select('id');
        $this->db->where('activation_code', $activation_code);
        $query = $this->db->get('users');

        if ($query->num_rows()>0) {

            $data = array(
                'status' => 1
            );
            $this->db->where('activation_code', $activation_code);

            return $this->db->update('users', $data);
        } else {
            return false;
        }
    }

    function verify_login($username, $password) {

        $this->db->where('username', $username);
        $this->db->where('password', $password);
        $query = $this->db->get('users');
        if ($query->num_rows() > 0) {

            return $query->result();
        } else {

            return False;
        }
    }

}

?> 